#################################################################
# TESTS
#################################################################

FILE(GLOB_RECURSE TESTS_SRC *.f90 *.F90)
SET(TESTS_SRC ${TESTS_SRC} PARENT_SCOPE)

#################################################################
# FoX LIBRARIES
#################################################################

LINK_DIRECTORIES(${THIRDPARTY_OUTPUT_PATH}/${FOX_LIB}/lib)
INCLUDE_DIRECTORIES(${THIRDPARTY_OUTPUT_PATH}/${FOX_LIB}/modules)

#################################################################
# EXTERNAL LIBRARIES
#################################################################

FOREACH(TEST_SRC ${TESTS_SRC})
    GET_FILENAME_COMPONENT(EXE_NAME ${TEST_SRC} NAME_WE)
    ADD_EXECUTABLE(${EXE_NAME} ${TEST_SRC})
    TARGET_LINK_LIBRARIES(${EXE_NAME} ${LIB})
    FOREACH (EXT_LIB ${EXT_LIBS})
        IF(DEFINED ${PROJECT_NAME}_ENABLE_${EXT_LIB} AND ${PROJECT_NAME}_ENABLE_${EXT_LIB} AND ${EXT_LIB}_FOUND)
            TARGET_LINK_LIBRARIES(${EXE_NAME} ${${EXT_LIB}_LIBRARIES})
        ENDIF()
    ENDFOREACH()

    FOREACH(FOX_LIB ${FOX_LIBS})
        TARGET_LINK_LIBRARIES(${EXE_NAME} ${FOX_LIB})
    ENDFOREACH()

    FOREACH(PENF_LIB ${PENF_LIBS})
        TARGET_LINK_LIBRARIES(${EXE_NAME} ${PENF_LIB})
    ENDFOREACH()

    IF(MPI_Fortran_COMPILER AND ${PROJECT_NAME}_ENABLE_MPI)
        TARGET_LINK_LIBRARIES(${EXE_NAME} ${MPI_Fortran_LIBRARIES})
    ENDIF()

    ADD_TEST(${EXE_NAME}_TEST ${EXECUTABLE_OUTPUT_PATH}/${EXE_NAME})
    SET_TESTS_PROPERTIES( ${EXE_NAME}_TEST PROPERTIES LABELS "SERIAL MPI" )
    IF(MPI_FOUND AND MPIEXEC AND MPIEXEC_NUMPROC_FLAG AND MPIEXEC_MAX_NUMPROCS)
        ADD_TEST(${EXE_NAME}_PARALLEL_TEST ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} ${EXECUTABLE_OUTPUT_PATH}/${EXE_NAME} ${MPIEXEC_POSTFLAGS})
        SET_TESTS_PROPERTIES( ${EXE_NAME}_PARALLEL_TEST PROPERTIES LABELS "PARALLEL MPI" )
    ENDIF()
ENDFOREACH()



